//
//  BGMCommonView.m
//  BGM
//
//  Created by 我要变好看 on 2018/12/18.
//  Copyright © 2018 com.alirtc.demo. All rights reserved.
//

#import "BGMAcceptView.h"
#import "Common.h"

@interface BGMAcceptView()<UITextViewDelegate>


@end


@implementation BGMAcceptView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self != nil) {
        self.backgroundColor = [UIColor clearColor];
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,SCREENW , SCREENH)];
        bgView.backgroundColor = [UIColor grayColor];
        bgView.alpha = 0.3;
        [self addSubview:bgView];
        
       
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Clickbg)];
        [self addGestureRecognizer:tap];
        
        
        UIView *accptView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW-80, 200)];
        accptView.backgroundColor = [UIColor whiteColor];
        accptView.layer.cornerRadius = 8;
        accptView.layer.masksToBounds = YES;
        [self addSubview:accptView];
        accptView.center = CGPointMake(SCREENW/2, SCREENH/2-50);
        
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15,15, 200, 30)];
        label.text = @"我帮的上这个忙";
        label.textColor = bgmmainColor;
        [accptView addSubview:label];
        
        self.textView  = [[UITextView alloc]initWithFrame:CGRectMake(15, 50, accptView.frame.size.width-30, 80)];
        self.textView.backgroundColor =bgmColor(244, 244, 244);
        self.textView.layer.cornerRadius = 8;
        self.textView.layer.masksToBounds = YES;
        self.textView.delegate = self;
        self.textView.returnKeyType = UIReturnKeyDone;
        [accptView addSubview:self.textView];
        
        UIButton *cancelBtn =[[UIButton alloc]initWithFrame:CGRectMake(15, 150, 80, 30)];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:bgmgrayColor forState:UIControlStateNormal];
        cancelBtn.layer.masksToBounds = YES;
        cancelBtn.layer.cornerRadius = 12;
        cancelBtn.layer.borderWidth = 1;
        cancelBtn.layer.borderColor = bgmyelloeColor.CGColor;
        cancelBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [accptView addSubview:cancelBtn];
        [cancelBtn addTarget:self action:@selector(ClickCanel) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *submitBtn =[[UIButton alloc]initWithFrame:CGRectMake(self.textView.frame.size.width-80, 150, 80, 30)];
        [submitBtn setTitle:@"确认" forState:UIControlStateNormal];
        [submitBtn setTitleColor:bgmgrayColor forState:UIControlStateNormal];
        submitBtn.layer.masksToBounds = YES;
        submitBtn.layer.cornerRadius = 12;
        submitBtn.backgroundColor = bgmyelloeColor;
        [accptView addSubview:submitBtn];
        
        [submitBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];

        
    }
    return self;
}
- (void)clickBtn{
    
    [self.textView resignFirstResponder];
    
    [self.acceptDelegate sendAccept:self.textView.text];
    
    
}
- (void)Clickbg{
    
    [self.textView resignFirstResponder];
    
//    [self.acceptDelegate hiddenAcceptView];
}
- (void)ClickCanel{
     [self.textView resignFirstResponder];
     [self.acceptDelegate hiddenAcceptView];
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}


@end
